package cn.threewaters.qtyy.config.dyds;

import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//@Component
//@Aspect
public class DataSourceInterceptor {

	Logger logger = LoggerFactory.getLogger(DataSourceInterceptor.class);

	@Pointcut(value = "execution(* cn.threewaters.qtyy.dit.one..*.*(..))")
	private void datasource1ServicePointcut() {
	};

	@Pointcut(value = "execution(* cn.threewaters.qtyy.dit.two..*.*(..))")
	private void datasource2ServicePointcut() {
	};

	/**
	 * 切换数据源1
	 */
	@Before("datasource1ServicePointcut()")
	public void dataSource1Interceptor() {
		logger.info("切换到数据源{}..............................", "datasource1");
		DbContextHolder.setDbType(DBTypeEnum.datasource1);
	}

	/**
	 * 切换数据源2
	 */
	@Before("datasource2ServicePointcut()")
	public void dataSource2Interceptor() {
		logger.info("切换到数据源{}..............................", "datasource2");
		DbContextHolder.setDbType(DBTypeEnum.datasource2);
	}

}
